package com.briup.app02.web.controller;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.briup.app02.bean.Article;
import com.briup.app02.bean.extend.ArticleExtend;
import com.briup.app02.service.IArticleService;
import com.briup.app02.utils.Message;
import com.briup.app02.utils.MessageUtil;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;

@Api(description="资讯相关接口")
@Validated
@RestController
@RequestMapping("/article")
public class ArticleController {
	
	@Autowired
	private IArticleService articleService;
	
	@ApiOperation("阅读文章")
	@GetMapping("read")
	public Message read(long id) {
		ArticleExtend article = articleService.read(id);
		return MessageUtil.success(article);
	}
	
	  @ApiOperation(value = "查询所有资讯")
	    @GetMapping("query")
	    public Message query(String title,String status,Long categoryId){
	        List<Article> list = articleService.query(title,status,categoryId);
	        return MessageUtil.success(list);
	    }
	  
	  @ApiOperation(value = "修改风采状态")
		@PostMapping("changeStatus")
		public Message changeStatus(Long id, String status) {
			articleService.changeStatus(id, status);
			return MessageUtil.success("审核完毕");
		}
	  
	  @ApiOperation(value = "级联查询所有资讯")
	    @GetMapping("queryCascade")
	    public Message queryCascade(String title,String status,Long categoryId){
	        List<ArticleExtend> list = articleService.queryCascade(title,status,categoryId);
	        return MessageUtil.success(list);
	    }
	   @ApiOperation(value="保存或更新资讯信息")
		@ApiImplicitParams({
			@ApiImplicitParam(name="id",value = "主键",paramType = "form"),
			@ApiImplicitParam(name="title",value = "标题",paramType = "form"),
			@ApiImplicitParam(name="content",value = "内容",paramType = "form"),
			@ApiImplicitParam(name="cover",value = "缩略图",paramType = "form"),
			@ApiImplicitParam(name="cotegoryId",value = "分类id",paramType = "form"),
			@ApiImplicitParam(name="authorId",value = "作者id",paramType = "form"),
			})
		@PostMapping("saveOrUpdate")
		public Message saveOrUpdate(Article article) {
			articleService.saveOrUpdate(article);
			return MessageUtil.success("更新成功");
		}
		 
	  @ApiOperation(value="根据id删除")
		@GetMapping("deleteById")
		@ApiImplicitParams({
			@ApiImplicitParam(name="id",value = "id",paramType = "query",required=true)
		})
		public Message deleteById(Long id) {
			articleService.deleteById(id);
			return MessageUtil.success("删除成功");
		}
}